<%@ page import="cn.myschool.entity.Student" %>
<%@ page import="cn.myschool.service.StudentService" %>
<%@ page import="cn.myschool.util.StrUtil" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.List" %>
<%@ page import="cn.myschool.pojo.Page" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        table td{
            text-align: center;
        }
    </style>
    <script src="js/jquery.js"></script>
</head>
<body>

<a href="addStudent.jsp">新生注册</a>
<%
    Page<Student> p= (Page<Student>)request.getAttribute("p");
    int pageNo= p.getPageNo();
    String wechat=(String)request.getAttribute("wechat");
    String qq=(String)request.getAttribute("qq") ;
    String sname=(String)request.getAttribute("sname");
    Date start=(Date)request.getAttribute("start");
    Date end=(Date)request.getAttribute("end");


%>
<p>
    <form action="student" id="seachForm">
     <input type="hidden" name="pageNo" id="pageNo" value="<%=pageNo%>"/>
     <input type="search" name="sname" placeholder="学生姓名" value="<%=sname%>"/>
     <input type="search" name="wechat" placeholder="wechat" value="<%=wechat%>"/>
     <input type="search" name="qq" placeholder="QQ" value="<%=qq%>"/>
     入学时间从:<input type="date" name="dateStart" value="<%=StrUtil.toStr(start)%>"/>-<input type="date" name="dateEnd"/>
    <input type="submit" value="搜索"/>
    </form>
</p>
<table border="1" cellpadding="0" cellspacing="0" align="center" style="width: 90%">
    <caption>学生信息</caption>
    <tr>
        <td>学号</td>
        <td>姓名</td>
        <td>性别</td>
        <td>入学时间</td>
        <td>QQ</td>
        <td>手机号</td>
        <td>微信</td>
        <td>操作</td>
    </tr>

    <%

        for (Student s : p.getDatas()) {
    %>
    <tr>
        <td><%=s.getStuno()%></td>
        <td><%=s.getSname()%></td>
        <td><%=s.getSex()%></td>
        <td><%=s.getEnterdate()%></td>
        <td><%=s.getQq()%></td>
        <td><%=s.getTelephone()%></td>
        <td><%=s.getWechat()%></td>
        <td>
            <a href="#">查看</a>
            <a href="#">修改</a>
            <a href="#">删除</a>
            <a href="showScore.do?stuno=<%=s.getStuno()%>">查看成绩</a>
            <a href="#?stuno=<%=s.getStuno()%>">添加成绩</a>
        </td>
    </tr>
    <%}%>
</table>
<p align="center" class="pager">
    <a id="prev" href="#" data-page="1">首页</a>
    <%
        if(pageNo>1){
    %>
    <a id="prev" href="#" data-page="<%=pageNo-1%>">上一页</a>
    <%}%>
    <input type="number" name="pa" value="<%=pageNo%>" style="width: 40px" size="4" min="1" max="<%=p.getTotalPages()%>"/>/<%=p.getTotalPages()%>
    <button type="button" id="gotoPage">Go</button>
    <%if (pageNo<p.getTotalPages()){%>
    <a href="#" id="next" data-page="<%=pageNo+1%>">下一页</a>
    <%}%>
    <a href="#" id="next" data-page="<%=p.getTotalPages()%>">最后一页</a>
</p>
<script>
    $(function () {
        $("form#seachForm :submit").click(function () {
            $("#pageNo").val(1);//每次搜索，页号从1开始
            return true;
        });
        $(".pager #gotoPage").click(function () {
            let pageNo=$(this).prev().val();
            if(pageNo<1 || pageNo><%=p.getTotalPages()%>){
                alert("值太大");
                return false;
            }
            $("form#seachForm #pageNo").val(pageNo);
            $("form#seachForm").submit();//手工提交表单
            return false;
        });
        $(".pager a").click(function () {
            let pageNo= $(this).data("page");
            //alert(pageNo);
            //$(this).attr("data-page");
            $("#pageNo").val(pageNo);
            $("form#seachForm").submit();//手工提交表单
            return false;//让a 链接失效
        });
    });
</script>
</body>
</html>
